home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_06 / gotwals / sqrt.cpp < prev    next >
Text File  |  1994-04-01  |  452b  |  16 lines

  1. ====================== Listing 7 ======================
  2. /* Compute the greatest integer less than or equal
  3.    to the square root of lint.  From "Factorization
  4.    and Primality Testing", Bressoud
  5.    ------------------------------------------------ */
  6. LargeInt sqrt(const LargeInt& lint) {
  7.    LargeInt a = lint;
  8.    LargeInt b = (lint + one) / two;
  9.  
  10.    while (b < a) {
  11.       a = b;
  12.       b = (a * a + lint) / (two * a);
  13.    }
  14.    return a;
  15. }
  16.